package com.fy.login;

import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;

/**
 * @author zhufeifei 2022/8/16
 **/

public class LoginContextWrapper {

    private final LoginContext context;
    private final BaseMetadata metadata;
    private final LoginType loginType;

    LoginContextWrapper(LoginContext loginContext, BaseMetadata metadata, LoginType type) throws LoginException {
        this.context = loginContext;
        this.metadata = metadata;
        this.loginType = type;
    }

    public BaseMetadata getMetadata() {
        return metadata;
    }

    public LoginContext getContext() {
        return context;
    }

    public Subject getSubject() {
        return context.getSubject();
    }

    public void logout() throws LoginException {
        LoginManager.logout(getLoginType(), getMetadata());
    }

    public LoginType getLoginType() {
        return loginType;
    }
}
